home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / BNCHMARK / MEMTSTR.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  3.2 KB  |  146 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <stat.h>
  4. #include <bios.h>
  5.  
  6. extern int errno;
  7.  
  8. struct disk_info {
  9.     unsigned long di_free; /* free allocation units */
  10.     unsigned long di_many; /* how many AUs on disk */
  11.     unsigned long di_ssize;/* sector size - bytes per sector*/
  12.     unsigned long di_spau; /* sectors per AU */
  13. };
  14.  
  15. main()
  16.  
  17. {
  18.  
  19.     int hand1, hand2;
  20.     int status;
  21.     char *buffer;
  22.     long copysize, rdsize, wrsize;
  23.     long fsect;
  24.     long fbyte;
  25.     long tsect;
  26.     long tbyte;
  27.     int dd;
  28.     struct disk_info dev;
  29.  
  30.     DMABUFFER mydta;
  31.  
  32.     dd = Dgetdrv();     /*the current partition, C is 2 */
  33.  
  34.     Dfree(&dev, dd+3);    /*add 1, because the Dfree thinks drive C is 3*/
  35.     fsect = dev.di_free*dev.di_spau;
  36.     tsect = dev.di_spau*dev.di_many;
  37.     fbyte = fsect*dev.di_ssize;
  38.     tbyte = tsect*dev.di_ssize;
  39.  
  40.     if ((hand1 = Fopen("a:\\memtst1.c", 0)) < 0)     {
  41.         fprintf(stderr, "\nCan't open input file.");
  42.         errno = -hand1;
  43.         perror("Fopen failed");
  44.         Pterm(1);
  45.     }
  46.     /*
  47.     if ((hand2 = Fopen("c:\\memtst1.cb", 1)) < 0)     {
  48.         fprintf(stderr, "\nCan't open input file.");
  49.         errno = -hand2;
  50.         perror("Fopen failed");
  51.         Pterm(1);
  52.     }
  53.     */
  54.     /*
  55.     Fsetdta(mydta=(struct DMABUFFER *)malloc(sizeof(struct DMABUFFER)));
  56.     */
  57.     Fsetdta(&mydta);
  58.  
  59.     if ((status=Fsfirst("a:\\memtst1.c", 0xf7)) != 0)    {
  60.         Fclose(hand1);
  61.         fprintf(stderr,"\nError getting stats on input file.");
  62.         errno = -status;
  63.         perror("Fopen failed");
  64.         Pterm(1);
  65.     }
  66.  
  67.     status = mydta.d_fattr & 7;
  68.     if ((hand2=Fcreate("c:\\memtst1.cmm", status)) < 0)    {
  69.         Fclose(hand1);
  70.         fprintf(stderr, "\nCan't creat a test file.");
  71.         errno = -hand2;
  72.         perror("Fcreat failed");
  73.         Pterm(1);
  74.     }
  75.     buffer = (char *)malloc(4096);
  76.     /*
  77.     tmp = buffer;
  78.     for (i=0; i < 4095; i++)    {
  79.         *tmp++ = '1';
  80.     }
  81.     *tmp = '0';
  82.     */
  83.  
  84.     rdsize = mydta.d_fsize;
  85.     wrsize = fbyte + 4*dev.di_ssize;
  86.     copysize = rdsize;
  87.  
  88.     while(copysize > 4096)    {
  89.         if ((status=Fread(hand1, 4096L, buffer)) < 0)    {
  90.             Fclose(hand1);
  91.             Fclose(hand2);
  92.             Fdelete("memtst1.cmm");
  93.             fprintf(stderr, "\nRead error on test file");
  94.             errno = -status;
  95.             perror("Read failure");
  96.             Pterm(1);
  97.         }
  98.         if ((status=Fwrite(hand2, 4096L, buffer)) < 0)    {
  99.             Fclose(hand1);
  100.             Fclose(hand2);
  101.             Fdelete("memtst1.cmm");
  102.             fprintf(stderr, "\nWrite error on test file");
  103.             errno = -status;
  104.             perror("Write failure");
  105.             Pterm(1);
  106.         }
  107.         copysize -= 4096;
  108.     }
  109.     if (copysize > 0)    {
  110.         if ((status=Fread(hand1, copysize, buffer)) < 0)    {
  111.             Fclose(hand1);
  112.             Fclose(hand2);
  113.             Fdelete("memtst1.cmm");
  114.             fprintf(stderr, "\nRead error on test file");
  115.             errno = -status;
  116.             perror("Read failure");
  117.             Pterm(1);
  118.         }
  119.         /*
  120.         if ((status=Fwrite(hand2, copysize, buffer)) < 0)    {
  121.             Fclose(hand1);
  122.             Fclose(hand2);
  123.             Fdelete("memtst1.cmm");
  124.             fprintf(stderr, "\nWrite error on test file");
  125.             errno = -status;
  126.             perror("Write failure");
  127.             Pterm(1);
  128.         }
  129.         */
  130.         if ((status=Rwabs(1, buffer, 1, 2050, 2)) < 0)    {
  131.             Fclose(hand1);
  132.             Fclose(hand2);
  133.             Fdelete("memtst1.cmm");
  134.             fprintf(stderr, "\nWrite error on test file");
  135.             errno = -status;
  136.             perror("Write failure");
  137.             Pterm(1);
  138.         }
  139.     }
  140.     Fclose(hand1);
  141.     Fclose(hand2);
  142.     printf("Test file was created\n");
  143.     Fsetdta(NULL);
  144.     Pterm0();
  145. }
  146.